#include "descr/descr_cultures_parser.h"


using namespace std;


bool DescrCulturesParser::parse(string line)
{
	string token = popNextToken(line);
	if (token.compare("culture") == 0)
	{
		string token = popNextToken(line);
		shared_ptr<Culture> culture(new Culture());
		culture->id = token;
		Culture::add(culture);
		parsingCulture = culture;
		state = DescrCulturesParser::CULTURE;
	}
	else if (token.compare("{") == 0)
	{
		state = (STATE) (state + 1);
	}
	else if (token.compare("}") == 0)
	{
		state = (STATE) (state - 1);
	}
	else
	{
		switch (state)
		{
			case DescrCulturesParser::SETTLEMENT_TYPE:
			{
				shared_ptr<Culture::Settlement> settlement(new Culture::Settlement);
				settlement->id = token;
				parsingSettlement = settlement;
				parsingCulture->settlementMap[token] = settlement;
			}
			break;

			case DescrCulturesParser::SETTLEMENT_DATA:
			{
				if (token.compare("normal") == 0)
				{
					string casPath = popNextToken(line);
					parsingSettlement->modelPath = basePath + casPath;
				}
				else if (token.compare("card") == 0)
				{
					string cardPath = popNextToken(line);
					parsingSettlement->cardPath = basePath + cardPath;
				}
			}
			break;
		}
	}

	return true;
}